package com.nf.health.app.datamain.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.utils.DateUtil;
import com.nf.health.app.utils.ViewUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 显示温度的测量结果
 */
public class TemperatureResultyActivity extends BaseActivity {
    @Bind(R.id.tv_time)
    TextView tv_time;
    @Bind(R.id.tv_temperature)
    TextView tv_temperature;
    @Bind(R.id.iv_measured_result_bk_temprerture)
    ImageView iv_measured_result_bk_temprerture;
    @Bind(R.id.btn_temperture_measure)
    Button btn_temperture_measure;

    private int images[] = {
            R.drawable.iv_posotion_one,
            R.drawable.iv_posotion_two,
            R.drawable.iv_posotion_three,
            R.drawable.iv_posotion_four,
            R.drawable.iv_posotion_five,
            R.drawable.iv_posotion_six,
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_temperture_measured_result);
        ButterKnife.bind(this);
        ViewUtil.setText(this, R.id.titlebar_title_tv, "测量结果");
        iv_measured_result_bk_temprerture.setAdjustViewBounds(true);
        btn_temperture_measure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        double temperature = getIntent().getDoubleExtra("tempererture",0);
        //显示测量结果
        initData(temperature);
        levelJudgmentByFat(temperature);

    }

    /**
     *
     * @param temperature
     * @return 健康等级
     */
    private int levelJudgmentByFat(double temperature) {
        int type = 1;
        if (temperature < 35.9) {
            type = 1 ;
        }
        else if (temperature < 37.2){
            type = 2 ;
        }
        else if (temperature < 38.0){
            type = 3 ;
        }
        else if (temperature < 39.0){
            type = 4 ;
        }
        else if (temperature < 41.0){
            type = 5 ;
        }
        else{
            type = 6 ;
        }
        type = type - 1 ;
        iv_measured_result_bk_temprerture.setImageResource(images[type]); //不会变形
        return type;
    }

    /**
     * 显示测量结果
     * 对象在sp中
     * 对应的参数类型有些混乱
     */
    private void initData(double temperature) {
        tv_time.setText(DateUtil.getCurrentDate());
        tv_temperature.setText(String.valueOf(temperature));

    }
}
